﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FourWayClimbingDemo.Chess.Advice
{
    public abstract class BaseAdvice
    {
        protected int _score = 10000;
        protected BaseAdvice _next;

        public void SetNextAdvice(BaseAdvice next) {
            this._next = next;
        }

        public virtual int Execute() {
            if (_next != null) _score += _next.Execute();
            return _score;
        }

        protected int GetScore(AdviceStatusEnum status) {

            int score = 0;

            switch (status) {
                case AdviceStatusEnum.当前_安全:
                    score = 0;
                    break;
                case AdviceStatusEnum.当前_被吃:
                    score = 1000;
                    break;
                case AdviceStatusEnum.走棋_走不通:
                    score = -10000;
                    break;
                case AdviceStatusEnum.走棋_没吃子:
                    score = 2000;
                    break;
                case AdviceStatusEnum.走棋_吃子:
                    score = 3000;
                    break;
                case AdviceStatusEnum.落子_安全:
                    score = 2000;
                    break;
                case AdviceStatusEnum.落子_被吃:
                    score = -3000;
                    break;
            }

            return score;
        }

        protected AdviceStatusEnum CompareAdviceStatus(AdviceStatusEnum old, AdviceStatusEnum status) {
            return status > old ? status : old;
        }

        protected Dir NegativeDir(Dir dir) {
            Dir ndir = Dir.LEFT;
            switch (dir) {
                case Dir.LEFT:
                    ndir = Dir.RIGHT;
                    break;
                case Dir.RIGHT:
                    ndir = Dir.LEFT;
                    break;
                case Dir.TOP:
                    ndir = Dir.BOTTOM;
                    break;
                case Dir.BOTTOM:
                    ndir = Dir.TOP;
                    break;
            }
            return ndir;
        }

    }


    public enum AdviceStatusEnum { 
        None = 0,
        当前_安全 =11,
        当前_被吃 =12,
        走棋_走不通 = 21,
        走棋_没吃子 =22,
        走棋_吃子 =23,
        落子_安全 =31,
        落子_被吃 =32

    }

}
